package io.renren.common.eth.web3j;
import java.math.BigDecimal;

import org.web3j.protocol.Web3j;
import org.web3j.protocol.admin.Admin;
import org.web3j.protocol.admin.JsonRpc2_0Admin;
import org.web3j.protocol.http.HttpService;
import org.web3j.protocol.core.JsonRpc2_0Web3j;

public class EthClient {
    private volatile static Web3j web3j;
    private volatile static Admin admin = null;
   // private static String RPC_URL = "https://mainnet.infura.io/0x76C6Bd07fD3c78D439fE32B790e4213F30ab39DB";
    private static String RPC_URL = "https://ropsten.infura.io/0x65623DaF4c2D623982e19Da7d9552bda5E1655c9";
    
    public static Web3j getWeb3jClient() {
        if (web3j == null) {
            synchronized (EthUtil.class) {
                if (web3j == null) {
                    web3j = new JsonRpc2_0Web3j(new HttpService(RPC_URL));
                }
            }
        }
        return web3j;
    }
    
    
  
    public static Admin getAdminClient() {
        if (admin == null) {
            synchronized (EthUtil.class) {
                if (admin == null) {
                    admin =  new JsonRpc2_0Admin(new HttpService(RPC_URL));
                }
            }
        }
        return admin;
    }

    public static void main(String[] args) throws Exception{
    	  
    	       System.out.println((EthUtil.getBalance("0x5a62f07785a8255e6c12db988c0361e237d49364")));
    	        
    	    	EthUtilTest ee = new EthUtilTest();
    	    	System.out.println("balance:"+ee.testGetTokenBalance("0x5a62f07785a8255e6c12db988c0361e237d49364"));
    	    	ee.tokenTransferFrom("0x5a62f07785a8255e6c12db988c0361e237d49364", "0x33efd42ca971e76843188e7dc12c709d14a9a2ac", "a0c72b7564b5b707bf08cfb3149773c8f42f62080d2663068d405c6d1087913d", new BigDecimal("50000.00"));  
    	    	
    }
}
